#ifndef	COMM_H
#define	COMM_H

#include "defines.h"

#define push_param		stack_push

enum itype
{
	na,
	w,
	uw,
	d,
	ud,
	f
};

enum mtype
{
	INV,
	LOG,
	EXP,
	SQRT,
	SIN,
	COS
};

//////////////////////////////////////////////////////////////////////

const char *inum2str(char buf[], int num, enum itype t, int positive = 1);

const char *float2str(char buf[], float num, int positive = 1);

const char *rnum2rname(char buf[], int num, enum itype t, int positive = 1);

inline int rnum2addr(int regnum)
{
	return BASE_ADDR_OFFSET + regnum * ADDR_PER_DWORD;
}

//////////////////////////////////////////////////////////////////////

int command_init(const char *filename, const char *l);

void command_terminate();

//////////////////////////////////////////////////////////////////////

void add_label(const char *l);

void add_comment(const char *c);

void condition(const char *reg);

//////////////////////////////////////////////////////////////////////

void macro_call(const char *l);

void macro_return();

void macro_EOT();

void macro_media_block_write(unsigned short surface);

void macro_push(int regpos, unsigned int size);

void macro_pop(int regpos, unsigned int size);

void push_param(const char *rname);

void push_linkage();

void pop_linkage();

//////////////////////////////////////////////////////////////////////

void command_mov(unsigned short oplen, const char *des, const char *src);

void command_add(unsigned short oplen, const char *des, const char *src0, const char *src1);

void command_mul(unsigned short oplen, const char *des, const char *src0, const char *src1);

void command_divint(unsigned short oplen, const char *des, const char *src0, const char *src1);

void command_modint(unsigned short oplen, const char *des, const char *src0, const char *src1);

void command_divmodint(unsigned short oplen, const char *des0, const char *des1, const char *src0,
					   const char *src1);

void command_powfloat(unsigned short oplen, const char *des, const char *src0, const char *src1);

void command_divfloat(unsigned short oplen, const char *des, const char *src0, const char *src1);

// one src operand math including INV,LOG,EXP,SQRT,SIN,COS
// float is the only type supported by mathfloat
void command_mathfloat(unsigned short oplen, const char *des, const char *src0, enum mtype t);

void command_cmp(unsigned short oplen, const char *type, const char *des, const char *src0,
				 const char *src1);

void command_asr(unsigned short oplen, const char *des, const char *src0, const char *src1);

void command_shl(unsigned short oplen, const char *des, const char *src0, const char *src1);

void command_jmpi(unsigned short oplen, const char *index);

//////////////////////////////////////////////////////////////////////

void output_lines(const char *str);

#endif							// end of COMM_H
